function bindData(rowData){
	var unemployedId = rowData.unemployedId;
	$('#unemployedId').val(unemployedId);
	
	if(rowData.knry=='1'){
		$('#addStaffButton').linkbutton('disable');
		$('#delStaffButton').linkbutton('disable');
		$('#updateStaffButton').linkbutton('disable');
	} else{
		$('#addStaffButton').linkbutton('enable');
		$('#delStaffButton').linkbutton('enable');	
		$('#updateStaffButton').linkbutton('enable');
	}
		
    $('#joblessSerGrid').datagrid({ 
    	url:'jobless/server/getJoblessServiceList',  
        idField:'id',
        queryParams:{
        	unemployedId:unemployedId
	    },
        rownumbers:true,
        fit:true,
        fitColumns:true,
        singleSelect:true,
        pagination:true,
        
        columns:[[ 
                  {field:'id',title:'主键',hidden:'true'}, 
                  {field:'unemployedId',title:'外键',hidden:'true'}, 
                  {title:'提供就业服务情况',colspan:4,align:'center'},
                  {title:'工作应聘情况',colspan:4,align:'center'},
                  {title:'就业情况',colspan:4,align:'center'}
                ],[
                  {field:'servicedate',title:'服务日期',width:90,align:'center',
                	     formatter:function(data){ 
                	    	 if(data!=null){
                	    		 var df = new Date(data);  
                                 return df.format("yyyy-MM-dd");       			   
          		             } else{
          		        	     return null;
          		             }
          	             }},  
                  {field:'guide',title:'职业指导',width:90,align:'center'}, 
                  {field:'intruduce',title:'职业介绍',width:90,align:'center'}, 
                  {field:'training',title:'技能培训',width:90,align:'center'}, 
                  {field:'jobfair',title:'参加招聘会',width:90,align:'center'}, 
                  {field:'recommend',title:'介绍工作',width:90,align:'center'}, 
                  {field:'applying',title:'应聘岗位',width:90,align:'center'}, 
                  {field:'employstate',title:'是否就业',width:90,align:'center'}, 
                  {field:'employdate',title:'就业日期',width:90,align:'center',
                	     formatter:function(data){ 
                	    	 if(data!=null){
                	    		 var df = new Date(data);  
                                 return df.format("yyyy-MM-dd");       			   
             		         } else{
             		        	 return null;
             		         }
             	         }},                 	        
                  {field:'status',title:'就业状态',width:90,align:'center'},
                  {field:'company',title:'单位名称',width:90,align:'center'}, 
                  {field:'position',title:'岗位',width:90,align:'center'}                
                ]]    	
    }); 
}

function addServer(){
	var curr_time = new Date();
	var strDate = curr_time.getFullYear()+"-"+(curr_time.getMonth()+1)+"-"+curr_time.getDate();
	$('#add_servicedate').datebox('setValue',strDate);	
	$('#addJoblessSer').window('open');
}

/**
 * 添加失业人员信息
 */
function insertJoblessSer(){
	$('#addServiceForm').form('submit',{
		url:'jobless/server/insertJoblessSer',
		queryParams:{
			unemployedId: $('#unemployedId').val()
		},
		success: function(data){
			data =  $.parseJSON(data);
			if(data.success == 'true'){
				$.messager.alert('提示','添加成功','info');
				$('#addJoblessSer').window('close');
				$('#addServiceForm').form('clear');
				$('#joblessSerGrid').datagrid('load');
			}else{
				$.messager.alert('提示',data.message,'info');
			}
		}
	});
	
//	$.ajax({
//		url:'jobless/server/insertJoblessSer',
//	    type:'post',
//	    async: false,
//	    data:$('#addServiceForm').serialize(),
//	    success:function(data){
//	    	data =  $.parseJSON(data);
//		    if(data.success == 'true'){
//		    	$.messager.alert('提示','保存成功','info');
//			    $('#addJoblessSer').window('close');
//			    $('#addServiceForm').form('clear');
//			    joblessSearch();
//		    }else{
//		    	$.messager.alert('提示',data.message,'info');
//		    }
//	    },
//	    error:function(data){
//	    	alert("ajax发生错误！");	
//	    }
//    });
}

$("#addJoblessSer").window({
	onClose:function(data){
		$('#addServiceForm').form('clear');
	}  		      
});

/**
 * 删除一条失业人员信息记录
 * 
 */
function delJoblessSer(){
	var rowData = $('#joblessSerGrid').datagrid('getSelected');
	if(rowData == undefined){
		$.messager.alert('消息','请选择一条数据');
	}else{
		$.messager.confirm('提示','确定要删除吗？',function(r){
			if(r){
				$.ajax({
					url:'jobless/server/deleteJoblessSer',
					type:'post',
					data:{
						id:rowData.id
					},
					success:function(data){
						data =  $.parseJSON(data);
						if(data.success == 'true'){
							$.messager.alert('提示','删除成功','info');
							$('#joblessSerGrid').datagrid('reload');
							$('#joblessSerGrid').datagrid('unselectAll');
						}else{
							$.messager.alert('提示',data.message,'info');
						}
					}
				});
			}
		});
	}
}

/**
 * 回显失业人员信息
 */
function getJoblessSer(){
	var rowData = $('#joblessSerGrid').datagrid('getSelected');
	if(rowData == undefined){
		$.messager.alert('消息','请选择一条数据');
	}else{
		$('#modifyJoblessSer').window('open');
//		alert(rowData.id);
		$.ajax({
				url:'jobless/server/getJoblessSer',
				type:'post',
				data:{
					id:rowData.id					
				},
				success: function (data) { 
					if(data==null){
						$('#modifyServiceForm').form('clear');
					}else{
						$('#modifyServiceForm').form('load',data);
					}
		        },
		        error:function(data){
		        	$('#modifyServiceForm').form('clear');
		        }
			});
		}
}

/**
 * 修改失业人员信息
 * 
 */
function modifyJobessSer(){
//	$('#modifyServiceForm').form('submit',{
//		url:'jobless/server/updateJoblessInfo',
//		success: function(data){
//			data =  $.parseJSON(data);
//			if(data.success == 'true'){
//				$.messager.alert('提示','修改成功','info');
//				$('#modifyJoblessSer').window('close');
//				$('#modifyServiceForm').form('clear');
//				$('#joblessSerGrid').datagrid('reload');
//				$('#joblessSerGrid').datagrid('unselectAll');
//			}else{
//				$.messager.alert('提示',data.message,'info');
//				$('#modifyJoblessSer').window('close');
//				$('#modifyServiceForm').form('clear');
//			}
//		}
//	});
	
	var modifyFlag = $('#modifyServiceForm').form('validate');
	if(modifyFlag==false){
		$.messager.alert('提示','表单填写不正确');
		return;
	}else{
		$.ajax({
			url:'jobless/server/updateJoblessSer',
			type:'post',
	        async: false,
	        data:$('#modifyServiceForm').serialize(),
	        success:function(data){
	        	data =  $.parseJSON(data);
		        if(data.success == 'true'){
		        	$.messager.alert('提示','保存成功','info');
			        $('#modifyJoblessSer').window('close');
			        $('#modifyServiceForm').form('clear');
			        $('#joblessSerGrid').datagrid('reload');
					$('#joblessSerGrid').datagrid('unselectAll');
		        }else{
		        	$.messager.alert('提示',data.message,'info');

		        }
	        },
	        error:function(data){
	        	alert("ajax发生错误！");	
	        }
        });
	}
}

/**
 * 日期格式化
 * @param value
 * @param row
 * @returns {String}
 */
function formatterDate(value) {
    var date = new Date(value);
    return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
}

function parserDate(s){
	//alert("parserDate");
	var t = Date.parse(s);
	if (!isNaN(t)){
		return new Date(t);
	} else {
		return new Date("1975-08-01");
	}
	
}